<?php
set_time_limit(0);
include_once(PATH_SQL . 'groupcategory_sql.php');
include_once(PATH_MODEL . 'groupcategory_model.php');
include_once(PATH_VIEW_ADMIN . 'groupcategory_view.php');

set_time_limit(0);
include_once (PATH_SQL . 'category_sql.php');
include_once (PATH_MODEL . 'category_model.php');
include_once (PATH_VIEW_ADMIN . 'category_view.php');
$oModelCat = new Model_Category();
$oViewCat = new View_Admin_CategoryManangement($oModelCat);


$oModel_group_category=new Model_GroupCategory();
$oView_group_category=new View_Admin_GroupCategory($oModel_group_category);
$sAction=$_REQUEST['sAction'];

//$oViewCat->displatChooseCategoryIndex($oModelCat);
switch($sAction)
{
	case '': 
	{ 	
		$_SESSION['test_count']=0;
		$oView_group_category->displayGroupCategoryIndex($oModel_group_category);
		$oView_group_category->displayListGroupCategory($oModel_group_category);
		$oModelCat->unsetData('group_status');
		break;
	}
	 case 'update_status':
    {
        $oModel_group_category->unsetData('group_id');
        $oModel_group_category->unsetData('group_status');
            
        if (count($_POST['hotel_page_sort'] > 0)) 
		{
            foreach ($_POST['hotel_page_sort'] as $sKey => $sValue) 
			{
                $oModel_group_category->setData('group_id', $sKey);
                $oModel_group_category->setData('group_status', intval($_POST['group_status'][$sKey]));
                $oModel_group_category->updateGroupCategory();
            }
        }
        
        redir('?sMod=groupcategory');
        break;
    }
    
    case 'do_delete':
    {
    	$id=$_GET['id'];
		$result = $oModel_group_category->deleteGroupCategory($id);
		if(!$result){
			redir('?sMod=groupcategory&status=delError');
		}else{
			redir('?sMod=groupcategory&status=delSuccess');
		}
        break;
    }
        
	case 'do_add_form':
	{
		$oView_group_category->displayGroupCategoryNew($oModel_group_category);
		break;
	}
	
	case 'list_child_category':
 	{
 		$oView_group_category->displayGroupCategoryNew($oModel_group_category);
 		$parent_id=$_REQUEST['parent_id'];
 		$oModelCat->setData('current_level',$_REQUEST['current_level']);
 		$oView_group_category->resultXML($oModelCat,'',$oView_group_category->ajax_displayListChildCateogry($oModelCat,$parent_id));
 		die();
 		break;
 	}
 	case 'list_parent_category':
 	{
 		$oView_group_category->displayGroupCategoryNew($oModel_group_category);
 		$oView_group_category->resultXML($oModelCat,'',$oView_group_category->ajax_displayListParentCategory($oModelCat));
 		die();
 		break;
 	}
 	case 'do_add_new':
 	{
 		if ($_POST['group_status'] == 'on')
            $oModel_group_category->setData('group_status', 1);
        else
            $oModel_group_category->setData('group_status', 0);
                
 		$check_insert=$oModel_group_category->insertGroupCategory();
 		if($check_insert)
 		{
 			redir('?sMod=groupcategory&status=addSuccess');
 		}
 		else
 		redir('?sMod=groupcategory&status=addFail');
 	}
 	case 'edit_form':
 	{
 		$id=$_GET['id'];
 		$oView_group_category->displayGroupCategoryEdit($oModel_group_category);
 		$oView_group_category->displayInfoGroupCategory($oModel_group_category,$id);
 		break;
 	}
 	case 'do_edit':
 	{
 	
		 	$oModel_group_category->setData('group_id',$_POST['group_id']);
        	if ($_POST['group_status'] == 'on')
                $oModel_group_category->setData('group_status', 1);
            else
                $oModel_group_category->setData('group_status', 0);
           	
			$result=$oModel_group_category->updateGroupCategory();
	
			if(!$result)
			{
				$sErrorMsg =  $oModel_group_category->aLanguage['ALERT']['form_cannot_submit'] . $sErrorMsg;
				$oModel_group_category->setErrorMsg($sErrorMsg);
			}
			else
			{
				redir('?sMod=groupcategory&status=updatesuccess');
			}
 		break;
 	}
 	
	//NOT USE NOW
	case 'ajax_do_list_category':
	{
		$oView_group_category->displayGroupCategoryNew($oModel_group_category);
		$oModel_group_category->setData('search_key',$_REQUEST['search_key']);
		$oView_group_category->resultXML('','',$oView_group_category->ajax_display_list_search_category($oModel_group_category));
		die();
		break;
	}
		
}
$oView_group_category->displayPage($oModel_group_category);